package com.example.blog.controller;

import com.example.blog.po.Article;
import com.example.blog.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class BlogController {

    @Autowired
    private BlogService blogService;

    @RequestMapping("/index")
    public String index(Model model,@RequestParam(defaultValue = "0") Integer pageNum){
        Page<Article> pageArticle = blogService.pageArticle(pageNum);
        model.addAttribute("page",pageArticle);

        model.addAttribute("pageSize",pageArticle.getPageable().getPageSize());
        model.addAttribute("pageNum",pageArticle.getPageable().getPageNumber());
        model.addAttribute("total",pageArticle.getTotalPages());
        return "client/index";
    }
//    @RequestMapping("/test")
//    public String test(Model model){
//        Page<Article> articles = blogService.pageArticle();
//        model.addAttribute("page",articles);
//        return "client/test";
//    }

}
